home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Using Images, Bitmaps, and Metafiles / Reading and Writing Metadata / Read / Unit1.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2002-02-15  |  1.9 KB  |  73 lines

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  7.   Dialogs, GDIPAPI, GDIPOBJ, GDIPUTIL, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Memo1: TMemo;
  12.     Button2: TButton;
  13.     procedure Button2Click(Sender: TObject);
  14.   private
  15.     { Private declarations }
  16.   public
  17.     { Public declarations }
  18.   end;
  19.  
  20. var
  21.   Form1: TForm1;
  22.  
  23. implementation
  24.  
  25. {$R *.dfm}
  26.  
  27. procedure TForm1.Button2Click(Sender: TObject);
  28. type
  29.   ArrItems = array of TPROPERTYITEM;
  30.   ac = array of char;
  31. var
  32.   bitmap: TGPBitmap;
  33.   size, count: UINT;
  34.   strPropertyType: String;
  35.   pPropBuffer: PPROPERTYITEM;
  36.   j: Integer;
  37. begin
  38.   bitmap:= TGPBitmap.Create('..\untitled.JPG');
  39.   bitmap.GetPropertySize(size, count);
  40.   memo1.Clear;
  41.   memo1.Lines.Add(format('There are %d pieces of metadata in the file.',[count]));
  42.   memo1.Lines.Add(format('The total size of the metadata is %d bytes.',[size]));
  43.   memo1.Lines.Add('');
  44.  
  45.   // GetAllPropertyItems returns an array of PropertyItem objects.
  46.   // Allocate a buffer large enough to receive that array.
  47.   //SetLength(pPropBuffer, count);
  48.   Getmem(pPropBuffer, Size);
  49.   ZeroMemory(pPropBuffer, Size);
  50.  
  51.   // Get the array of PropertyItem objects.
  52.   bitmap.GetAllPropertyItems(size, count, pPropBuffer);
  53.  
  54.   // For each PropertyItem in the array, display the id, type, and length.
  55.   for j := 0 to count - 1 do
  56.   begin
  57.     // Convert the property type from a WORD to a string.
  58.     strPropertyType := ValueTypeFromULONG(ArrItems(pPropBuffer)[j].type_);
  59.     memo1.Lines.Add(format('Property Item %d', [j]));
  60.     memo1.Lines.Add(format('  id: %s ($%x)', [GetMetaDataIDString(ArrItems(pPropBuffer)[j].id),ArrItems(pPropBuffer)[j].id]));
  61.     memo1.Lines.Add(format('  type: %s (%d)', [strPropertyType, j]));
  62.     memo1.Lines.Add(format('  length: %d bytes', [ArrItems(pPropBuffer)[j].length]));
  63.     memo1.Lines.Add('');
  64.   end;
  65.  
  66.   FreeMem(pPropBuffer, Size);
  67.   bitmap.Free;
  68. end;
  69.  
  70.  
  71.  
  72. end.
  73.